package com.example.huang.service.impl;

import com.example.huang.entity.MyResult;
import com.example.huang.entity.User;
import com.example.huang.mapper.LoginMapper;
import com.example.huang.service.LoginService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@MapperScan(basePackages="com.example.demo.mapper")
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    @Override
    public MyResult login(User user) {
        User user1 = new User();
        List<User> userList = new ArrayList<>();
        userList =  loginMapper.login(user);
        MyResult myResult = new MyResult();
        if(userList.size()!=0) {
            myResult.setCode(0);
            myResult.setMsg("登录成功！");
            //myResult.setList(userList);
            System.out.println("成功!");
            myResult.setObject(userList.get(0));
        }else
        {
            myResult.setCode(1);
            myResult.setMsg("登录失败!");
        }
        return myResult;
    }
}